/* 
Copyright DAUPHIN Maxime 2005

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
http://www.gnu.org/licenses/gpl.txt
*/
#ifndef __WND_H__
#define __WND_H__

#include "Gui.h"

namespace Gui {

class Dc;
class Rect;

class Wnd
{
	static std::map<HWND,Wnd*> m_Wnds;
	static LRESULT CALLBACK globalWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);	
	virtual LRESULT CALLBACK wndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
	void setHandle(HWND hWnd) { m_hWnd = hWnd; }
protected:
	static HINSTANCE g_hInstance;
	WNDCLASS m_wc;
	HWND	m_hWnd;;
	STRING m_className;
	STRING m_windowName;
	DWORD	m_style;
	int		m_x;
	int		m_y;
	int		m_width;
	int		m_height;
	Wnd		*m_pParent;
	HWND	m_hWndNextViewer;

public:

	Wnd(void);
	virtual ~Wnd(void);
	void create(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow);
	void create(Wnd* pParent);
	int pumpMessage();
	//HWND getHandle() const;
	operator HWND(void) const;
	virtual void setText(const STRING text);
	virtual bool showWindow(int nCmdShow);
	virtual bool setWindowPos( HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags = 0 );
	virtual Rect getClientRect(void) const;
	virtual Rect getWindowRect(void) const;
	virtual Point screenToClient(const Point point) const;
	virtual Point clientToScreen(const Point point) const;

	virtual int onCreate();
	virtual int onDestroy();
	virtual int onCommand(int command);
	virtual int onSize(int width, int height);
	virtual int onChangeCbChain(HWND hWnd);
	virtual int onDrawClipBoard();
	virtual int onHook(LPARAM lParam);
	virtual int onPaint(Dc *pDc);
	virtual int onMouseMove(Point point);
	virtual int onLButtonUp(Point point, WPARAM wParam);

	virtual void move(int x, int y, int width, int height, bool repaint = true);
	virtual void move(const Rect rect, bool repaint);
	virtual int messageBox( const STRING text, const STRING caption = _T("Error"), const UINT uType = 0 );

	static HINSTANCE getHandleInstance(void);

};

class WndError 
{
public:
	enum WndErrorType {
		errUnknow,
		errSetText
	};
protected:
	WndErrorType		m_err;
public :
	WndError(WndErrorType err=errUnknow)
		: m_err(err) {}
	WndErrorType getError() { return m_err; }
};


};
#endif //__WND_H__
